package com.ruoyi.web.controller.lwpq;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.lwpq.domain.LwpqKhgl;
import com.ruoyi.lwpq.service.ILwpqKhglService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * khglController
 * 
 * @author ruoyi
 * @date 2022-03-17
 */
@Controller
@RequestMapping("/lwpq/khgl")
public class LwpqKhglController extends BaseController
{
    private String prefix = "lwpq/khgl";

    @Autowired
    private ILwpqKhglService lwpqKhglService;

    @RequiresPermissions("lwpq:khgl:view")
    @GetMapping()
    public String khgl()
    {
        return prefix + "/khgl";
    }

    /**
     * 查询khgl列表
     */
    @RequiresPermissions("lwpq:khgl:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(LwpqKhgl lwpqKhgl)
    {
        startPage();
        lwpqKhgl.setCreateBy(getLoginName());
        List<LwpqKhgl> list = lwpqKhglService.selectLwpqKhglList(lwpqKhgl);
        return getDataTable(list);
    }

    /**
     * 导出khgl列表
     */
    @RequiresPermissions("lwpq:khgl:export")
    @Log(title = "khgl", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(LwpqKhgl lwpqKhgl)
    {
        List<LwpqKhgl> list = lwpqKhglService.selectLwpqKhglList(lwpqKhgl);
        ExcelUtil<LwpqKhgl> util = new ExcelUtil<LwpqKhgl>(LwpqKhgl.class);
        return util.exportExcel(list, "khgl数据");
    }

    /**
     * 新增khgl
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存khgl
     */
    @RequiresPermissions("lwpq:khgl:add")
    @Log(title = "khgl", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(LwpqKhgl lwpqKhgl)
    {
        lwpqKhgl.setCreateBy(getLoginName());
        return toAjax(lwpqKhglService.insertLwpqKhgl(lwpqKhgl));
    }

    /**
     * 修改khgl
     */
    @RequiresPermissions("lwpq:khgl:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        LwpqKhgl lwpqKhgl = lwpqKhglService.selectLwpqKhglById(id);
        mmap.put("lwpqKhgl", lwpqKhgl);
        return prefix + "/edit";
    }

    /**
     * 修改保存khgl
     */
    @RequiresPermissions("lwpq:khgl:edit")
    @Log(title = "khgl", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(LwpqKhgl lwpqKhgl)
    {
        lwpqKhgl.setUpdateBy(getLoginName());
        return toAjax(lwpqKhglService.updateLwpqKhgl(lwpqKhgl));
    }

    /**
     * 删除khgl
     */
    @RequiresPermissions("lwpq:khgl:remove")
    @Log(title = "khgl", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(lwpqKhglService.deleteLwpqKhglByIds(ids));
    }
}
